package com.zy.news.controller;

import com.zy.news.entity.User;
import com.zy.news.mapper.UserMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "用户管理")
@RestController
@RequestMapping("user")
public class UserController {

    @Resource
    private UserMapper userMapper;

    @ApiOperation(value = "查询用户列表")
    @GetMapping
    public List<User> findAll(){
        return userMapper.selectList(null);
    }

    @PostMapping
    @ApiOperation(value = "注册用户")
    public int add(@RequestBody User u){
        return userMapper.insert(u);
    }

    @ApiOperation(value = "删除用户")
    @DeleteMapping
    public int del(int id){
        return userMapper.deleteById(id);
    }

    @ApiOperation(value = "用户登录")
    @GetMapping("/login")
    public User login(User u){
        return userMapper.login(u);
    }

    @ApiOperation(value = "修改用户信息")
    @PutMapping
    public int edit(User u){
        return userMapper.updateById(u);
    }
}
